program	fourth_order_runge_kutta
implicit none
real	::	k1,k2,k3,k4,h=0.2,t=0,y=1
integer	::	i,j,n
n=4/h

open(1,file='fork1.dat')
	write(1,*) t,y
do	i=1,n
	k1=f(t,y)
	k2=f(t+0.5*h,y+0.5*h*k1)
	k3=f(t+0.5*h,y+0.5*h*k2)
	k4=f(t+h,y+h*k3)
	y=y+h*(k1+2*k2+2*k3+k4)/6
	t=t+h
	write(1,*) t,y
end do


h=0.1;t=0;y=1
n=4/h
open(2,file='fork2.dat')
	write(2,*) t,y
do	i=1,n
	k1=f(t,y)
	k2=f(t+0.5*h,y+0.5*h*k1)
	k3=f(t+0.5*h,y+0.5*h*k2)
	k4=f(t+h,y+h*k3)
	y=y+h*(k1+2*k2+2*k3+k4)/6
	t=t+h
	write(2,*) t,y
end do


contains
	function	f(t,y)
	real,	intent(in)	::	t,y
	real				::	f
	f=-y+t*t
	end function
end program
